import axios from "~/axios";
import { queryFilters } from "~/composables/util";

import {useStore} from "vuex"

const store = useStore()


// 获取套餐列表
export function getSkusList({ ...data }) {
    let r = queryFilters(data)
    return axios.get(`/platefrom/skus/${r}`)
}


// 获取绑定的用户-套餐列表
export function getSkusBindList({ ...data }) {
    let r
    if(data != {}){
        r = queryFilters(data)
    }else{
        r = ''
    }
    
    return axios.get(`/platefrom/skus_bind/${r}`)
}

// 新增套餐
export function postSkus(data) {
    if (data.content_type) {
        data['content_type_ids'] = data.content_type.join(",")
    }
    if (data.platefrom) {
        data['platefrom_ids'] = data.platefrom.join(",")
    }
    return axios.post(`/platefrom/skus/`, data)
}


// 修改套餐
export function putSkus(id, data) {
    return axios.put(`/platefrom/skus/${id}/`, data)
}


// 新增套餐
export function postSkusBind(data) {
    return axios.post(`/platefrom/skus_bind/`, data)
}


// 绑定套餐
export function putSkusBind(id, data) {
    return axios.put(`/platefrom/skus_bind/${id}/`, data)
}


// 修改套餐激活状态
export function patchSkusStatus(id, status) {
    return axios.patch(`/platefrom/skus/${id}/`, { status })
}

// 批量删除套餐
export function deleteSkus(ids) {
    ids = Array.isArray(ids) ? ids : [ids]
    return axios.post(`/platefrom/skus/delete_all/`, { ids })
}

// 获取绑定的用户-套餐
export function getSkusByAccountID({id,group_id,company_id}) { 
    return axios.post(`/platefrom/skus_bind/by_user/`,{id,group_id,company_id})
}


